package kyssion.leetcode.num101_150;

import java.util.ArrayList;
import java.util.List;

public class code118_杨辉三角形 {
    public List<List<Integer>> generate(int numRows) {
        if (numRows < 1) {
            return new ArrayList<>();
        }
        List<List<Integer>> listList = new ArrayList<>();
        for (int a = 0; a < numRows; a++) {
            List<Integer> list = new ArrayList<>();
            if(a==0){
                list.add(1);
            }else{
                List<Integer> before = listList.get(a-1);
                for(int b=0;b<=before.size();b++){
                    if(b==0||b==before.size()){
                        list.add(1);
                    }else{
                        list.add(before.get(b-1)+before.get(b));
                    }
                }
            }
            listList.add(list);
        }
        return listList;
    }
}
